home *** CD-ROM | disk | FTP | other *** search
/ Magnum One / Magnum One (Mid-American Digital) (Disc Manufacturing).iso / d17 / proff.arc / PROFF.C < prev    next >
Text File  |  1988-02-17  |  9KB  |  312 lines

  1. char *version = "v.1.1";
  2.  
  3. #include <stdio.h>
  4. #include <ctype.h>
  5. #include "debug.h"
  6. #include "defs.h"
  7. #include "lookup.h"
  8.  
  9.  
  10. /*
  11.  * G L O B A L S
  12.  *
  13.  */
  14. #ifndef vms
  15. #define globaldef
  16. #endif
  17.  
  18.     /* next available char; init = 0 */
  19. globaldef int bp = -1;
  20.     /* pushed-back characters */
  21. globaldef char buf[BUFSIZE];
  22.     /* stack of file descriptors */
  23. globaldef FILE *infile[NFILES];
  24.     /* current file is infile[level] */
  25. globaldef int level;
  26.     /* stack of output file descriptors */
  27. globaldef FILE *outfile[NFILES];
  28.     /* current output is outfile[olevel]; */
  29. globaldef int olevel;
  30.     /* current output file pointer */
  31. globaldef FILE *poutput;
  32.     /* number registers a..z */
  33. globaldef int nr[26] = {  0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  34.               0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 };
  35.     /* system registers a..z */
  36. globaldef int sr[26] = {  0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  37.               0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 };
  38.     /* last char position in outbuf; init = 0 */
  39. globaldef int outp = 0;
  40.     /* width of text currently in outbuf; init = 0 */
  41. globaldef int outw = 0;
  42.     /* number of words in outbuf; init = 0 */
  43. globaldef int outwds = 0;
  44.     /* lines to be filled collect here */
  45. globaldef char outbuf[MAXOUT];
  46.                        /* word in outbuf; init=0 */
  47.     /* current output page number; init = 0 */
  48. globaldef int curpag = 0;
  49.     /* next output page number; init = 1 */
  50. globaldef int newpag = 1;
  51.     /* next line to be printed; init = 0 */
  52. globaldef int lineno = 0;
  53.     /* page length in lines; init = PAGELEN = 66 */
  54. globaldef int plval = PAGELEN;
  55.     /* page length save area */
  56. globaldef int savpl = PAGELEN;
  57.     /* margin before and including header */
  58. globaldef int m1val = 3;
  59.     /* margin after header */
  60. globaldef int m2val = 2;
  61.     /* margin after last text line */
  62. globaldef int m3val = 2;
  63.     /* bottom margin, including footer */
  64. globaldef int m4val = 3;
  65.     /* last live line on page, = plval-m3val-m4val */
  66. globaldef int bottom = PAGELEN - 5;
  67.     /* top of page title for even pages;init=NEWLINE */
  68. globaldef char ehead[MAXLINE];
  69.     /* top of page title for odd  pages;init=NEWLINE */
  70. globaldef char ohead[MAXLINE];
  71.     /* left,right margins for even header;init=inval,rmval */
  72. globaldef int ehlim[2] = { 0, PAGEWIDTH };
  73.     /* left,right margins for odd  header;init=inval,rmval */
  74. globaldef int ohlim[2] = { 0, PAGEWIDTH };
  75.     /* bot of page title for even pages;init=NEWLINE */
  76. globaldef char efoot[MAXLINE];
  77.     /* bot of page title for odd  pages;init=NEWLINE */
  78. globaldef char ofoot[MAXLINE];
  79.     /* left,right margins for even footer;init=inval,rmval */
  80. globaldef int eflim[2] = { 0, PAGEWIDTH };
  81.     /* left,right margins for odd  footer;init=inval,rmval */
  82. globaldef int oflim[2] = { 0, PAGEWIDTH };
  83.     /* flag for pausing between pages */
  84. globaldef int stopx = 0;
  85.     /* first page to begin printing with */
  86. globaldef int frstpg = 0;
  87.     /* last page to be printed */
  88. globaldef int lastpg = HUGE;
  89.     /* flag to indicate whether page should be printed */
  90. globaldef int print = YES;
  91.     /* number of blanks to offset page by; init = 0 */
  92. globaldef int  offset = 0;
  93.     /* verbose option; init = NO */
  94. globaldef int verbose = NO;
  95.     /* bolding option; init = YES; */
  96. globaldef char bolding = YES;
  97.     /* fill if YES; init = YES */
  98. globaldef int fill = YES;
  99.     /* current line spacing; init = 1 */
  100. globaldef int lsval = 1;
  101.     /* current indent; >= 0; init = 0 */
  102. globaldef int inval = 0;
  103.     /* current right margin; init = PAGEWIDTH = 60 */
  104. globaldef int rmval = PAGEWIDTH;
  105.     /* current temporary indent; init = 0 */
  106. globaldef int tival = 0;
  107.     /* number of lines to center; init = 0 */
  108. globaldef int ceval = 0;
  109.     /* flag for continuous center */
  110. globaldef char CEon = FALSE;
  111.     /* number of lines to underline; init = 0 */
  112. globaldef int ulval = 0;
  113.     /* flag for continuous underline */
  114. globaldef char ULon = FALSE;
  115.     /* number of lines to boldface; init = 0 */
  116. globaldef int boval = 0;
  117.     /* flag for continuous bolding */
  118. globaldef char BDon = FALSE;
  119.     /* justification types for heads and foots; */
  120.     /* init = LEFT, CENTER, RIGHT */
  121. globaldef int tjust[3] = { LEFT, CENTER, RIGHT };  
  122.     /* number of lines to blank suppress; init=0 */
  123. globaldef int bsval = 0;
  124.     /* right justify filled lines if YES; init=YES */
  125. globaldef int rjust = YES;
  126.     /* tab stops; init every 8 spaces */
  127. globaldef int tabs[INSIZE];
  128.     /* line control character; init = PERIOD */
  129. globaldef char cchar = '.';
  130.     /* universal escape - init = UNDERBAR */
  131. globaldef char genesc = '_';
  132.     /* character used to underline a BLANK; init = BLANK */
  133. globaldef char ulblnk = ' ';
  134.     /* scratch arrays for use by various routines */
  135. globaldef char tbuf1[MAXLINE];
  136. globaldef char tbuf2[MAXLINE];
  137. globaldef char tbuf3[MAXLINE];
  138. globaldef char ttl[MAXLINE];
  139.     /* flag to process runoff symbols only */
  140. globaldef char onlyrunoff = NO;
  141.     /* Flag to turn paging off */
  142. globaldef char paging = YES;
  143.     /* page number in roman numerals. Init = NO */
  144. globaldef char roman = NO;
  145.     /* autopar flag. Init = NO */
  146. globaldef char autopar = NO;
  147.     /* temporary indent value for autopar */
  148. globaldef int autoprv = 5;
  149.     /* hash tables for macros and variables */
  150. globaldef struct hashlist *macrotab[HASHMAX];
  151. globaldef struct hashlist *gentab[HASHMAX];
  152.     /* linked list entries for contents    */
  153. globaldef struct clist *chead = NULL;
  154. globaldef struct clist *clast = NULL;
  155.     /* keep track of what is done - VERBOSE */
  156. globaldef int p_txtlines = 0;
  157. globaldef int p_outlines = 0;
  158. globaldef int p_outpages = 0;
  159. globaldef int p_memoryus = 0;
  160.  
  161.  
  162.  
  163. /*
  164.  * M A I N L I N E   OF   P R O F F
  165.  *
  166.  */
  167.  
  168. main(argc,argv)
  169. int argc;
  170. char *argv[];
  171. {
  172.         int i,j,val,type;
  173.         char *p,c;
  174.         FILE *fp;
  175.  
  176.         for (i = 1; i < argc; i++) {
  177.                 p = argv[i];
  178.                 if (*p == '-') {
  179.                         ++p;
  180.                         if (isalpha(*p)) {
  181.                                 c = *p++;
  182.                                 switch(c) {
  183.  
  184. /* verbose stats */        case 'v':
  185.                 case 'V':
  186.                     verbose = TRUE;
  187.                     break;
  188. /* runoff only   */        case 'r':
  189.                 case 'R':
  190.                     onlyrunoff = TRUE;
  191.                     break;
  192. /* stop for page */             case 's':
  193.                                 case 'S':
  194.                                         stopx = 1;
  195.                                         break;
  196. /* page offset   */             case 'p':
  197.                                 case 'P':
  198.                                         if (*p == 'o' || *p == 'O') {
  199.                                                 p++;
  200.                                                 j = 0;
  201.                                                 val = getval(p, &j, &type);
  202.                                                 set(&offset, val, type, 0, 0,
  203.                                                     rmval - 1);
  204.                                         }
  205.                                         else
  206.                                                 usage();
  207.                                         break;
  208. /* include file  */         case 'i':
  209.                 case 'I': /* simulate .so <filename> */
  210.                     pbstr("\n");
  211.                     pbstr(p);
  212.                     pbstr(".so ");
  213.                     break;
  214.  
  215. /* disable some  */        case 'd':
  216.                 case 'D':
  217.                     switch (*p) {
  218.  
  219.                     case 'b':
  220.                     case 'B':
  221.                         bolding = NO;
  222.                         break;
  223.                     case 'p':
  224.                     case 'P':
  225.                         paging = NO;
  226.                         break;
  227.                     default:
  228.                         break;
  229.                     }
  230.                     break;
  231.  
  232. /* garbage       */             default:
  233.                                         usage();
  234.                                 }
  235.                         }
  236.                         else
  237.                      lastpg = atoi(p);
  238.                 }
  239.                 else if (*p == '+') {
  240.                         p++;
  241.                         if ((frstpg = atoi(p)) == 0)
  242.                                 usage();
  243.                 }
  244.                 else
  245.                         break;
  246.         }
  247.         if (i == argc)
  248.                 usage();
  249.         if ((fp = fopen(argv[i], "r")) == NULL) {
  250.                 fprintf(stderr, "%s: cannot open.\n",argv[i]);
  251.                 exit(1);
  252.         }
  253.         if ((p = argv[++i]) != 0) {
  254.                 if ((outfile[0] = fopen(p, "w")) == NULL) {
  255.                         fprintf(stderr,"%s: cannot create.\n\n", p);
  256.                         exit(1);
  257.                 }
  258.     }
  259.     else
  260.         outfile[0] = stdout;
  261.             /* set output file level */
  262.     olevel = 0;
  263.     poutput = outfile[0];
  264.     /*
  265.      * some minor initialisation
  266.      */
  267.  
  268.     for (i = 0; i < INSIZE; i++)
  269.         if (i % 8 == 0)
  270.             tabs[i] = YES;
  271.         else
  272.             tabs[i] = NO;
  273.  
  274.     ehead[0] = '\n';
  275.     ehead[1] = EOS;
  276.     ohead[0] = '\n';
  277.     ohead[1] = EOS;
  278.     efoot[0] = '\n';
  279.     efoot[1] = EOS;
  280.     ofoot[0] = '\n';
  281.     ofoot[1] = EOS;
  282.  
  283.             /* initialise contents linked list */
  284.  
  285.     chead = (struct clist *) malloc(sizeof(struct clist));
  286.     clast = chead;
  287.     p_memoryus += sizeof(struct clist);
  288.  
  289.         doroff(fp);
  290.         lbrk();
  291.         if (plval <= 100 && (lineno > 0 | outp > 0))
  292.                 space(HUGE);
  293.         putchar('\n');
  294.  
  295.     if(verbose) {
  296.         fprintf(stderr,"proff read in %6d textlines to produce\n",
  297.             p_txtlines);
  298.         fprintf(stderr,"              %6d lines\n",
  299.             p_outlines);
  300.         fprintf(stderr,"              %6d pages of formatted text.\n",
  301.             p_outpages);
  302.         fprintf(stderr,"\n%d bytes of memory was required\n",
  303.             p_memoryus);
  304.         fprintf(stderr,"for internal tables and lists.\n");
  305.     }
  306. #ifdef vms
  307.         exit(1);
  308. #else
  309.         exit(0);
  310. #endif
  311. }
  312.